package com.wing.user.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wing.user.dao.RoleMenuDao;
import com.wing.user.model.entity.RoleMenu;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 角色菜单-ServiceImpl
 *
 * @author
 */
@Service
@Slf4j
public class RoleMenuServiceImpl extends ServiceImpl<RoleMenuDao, RoleMenu> implements RoleMenuService {

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean add(List<RoleMenu> roleMenuList) {
        if(roleMenuList == null || roleMenuList.size() <= 0){
            return false;
        }
        this.baseMapper.delete(new QueryWrapper<RoleMenu>().eq("role_id", roleMenuList.get(0).getRoleId()));
        return saveBatch(roleMenuList);
    }

    @Override
    public int addRoleMenu(Long roleId) {
        return baseMapper.addRoleMenu(roleId);
    }

}
